package com.aimaterials.resource.util;

import java.io.File;

public class FFmpegBuilderTest {

    public static void main(String[] args) throws FFmpegCommandException {

        String ffmpegExePath = "E:\\VideoHandler\\ffmpeg-win64-gpl\\bin\\ffmpeg.exe";

        String finalPath = "D:\\course2\\";
        //文件名
        String fileName="28";
        //文件扩展名
        String fileExt=".mp4";

        String inputFilePath =finalPath+fileName+fileExt;

        String outputFilePath =finalPath+fileName+File.separator+fileName+fileExt;

        String m3u8Path=finalPath+fileName;

        File file=new File(finalPath+fileName);
        if(!file.exists()||!file.isDirectory()){
            file.mkdirs();
        }


        FFmpegCommandBuilder builder = new FFmpegCommandBuilder(ffmpegExePath);
        builder.input(inputFilePath).forceCode("libx264").strict("2")
                .output(outputFilePath);
        FFmpegCommand command = builder.build();
        try {
            String result = command.start(null);
            System.out.println(result);


        } catch (FFmpegCommandException e) {
            e.printStackTrace();
        }
        System.out.println("视频转码程序执行完毕，开始执行视频切片");

        FFmpegCommandBuilder builderCut = new FFmpegCommandBuilder(ffmpegExePath);
        builderCut.input(outputFilePath).cutVideo().segmentList(fileName,finalPath);
        FFmpegCommand commandCut = builderCut.build();
        try {
            String result = commandCut.start(null);
            System.out.println(result);
        } catch (FFmpegCommandException e) {
            e.printStackTrace();
        }

        System.out.println("视频切片完毕，开始执行图片截取");

        FFmpegCommandBuilder builderPic = new FFmpegCommandBuilder(ffmpegExePath);
        builderPic.input(outputFilePath).cutPic(fileName,finalPath);
        FFmpegCommand commandPic = builderPic.build();
        try {
            String result = commandPic.start(null);
            System.out.println(result);
        } catch (FFmpegCommandException e) {
            e.printStackTrace();
        }

    }

}
